package com.jgsu.farm.controller;

import com.jgsu.farm.service.StressFeatureService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(value = "farm/sysuser/stressfeature", tags = "胁迫特征管理模块")  //描述信息用的，标注在类上
@RestController
@RequestMapping("farm/sysuser/stressfeature")
public class StressFeatureController {
    @Autowired
    StressFeatureService stressFeatureService;

    /**
     * 胁迫特征管理API，待扩展。。。
     *
     * */

  /*  *//**
     * 胁迫特征添加
     *//*
    @ApiOperation(value = "胁迫特征添加功能")
    @PostMapping(value = "/add", produces = "application/json")
    public CommonResult stressFeatureAdd(Stressfeature stressfeature,
                                         @PathVariable(value = "file1", required = false) MultipartFile file1,
                                         @PathVariable(value = "file2", required = false) MultipartFile file2) throws IOException {

        try {
            // 实现文件上传
            DownLoadFiles downLoadFiles = new DownLoadFiles();
            String paramfile = downLoadFiles.DownLoadPhoto(file1);
            String vectfile = downLoadFiles.DownLoadPhoto(file2);
            stressfeature.setParamfile(paramfile);
            stressfeature.setVectfile(vectfile);

            stressFeatureService.add(stressfeature.getStresstype(), paramfile, vectfile);
            log.info("胁迫特征信息添加，胁迫特征id为：" + stressfeature.getStessid());
            return CommonResult.success(ResultCode.SUCCESS);
        } catch (DataAddException e) {
            log.error("胁迫特征信息添加异常,id为：{}", stressfeature.getStessid());
            throw new DataAddException(e.getCode(), e.getMessage());
        } catch (FileException fe) {
            throw new FileException(fe.getCode(), fe.getMessage());
        } catch (IOException e) {
            e.getMessage();
            throw new IOException("IO异常");
        }
    }

    *//**
     * 胁迫特征删除
     *//*
    @ApiOperation(value = "胁迫特征删除功能")
    @PostMapping(value = "/delete", produces = "application/json")
    public CommonResult stressFeatureDelete(@RequestParam("stessid") Integer stessid) {
        try {
            stressFeatureService.delete(stessid);
            log.info("删除id为：" + stessid + "的胁迫特征信息");
        } catch (DataNotExistException d) {
            log.error("不存在id为：" + stessid + "的胁迫特征信息，删除失败");
            throw new DataNotExistException(d.getCode(), d.getMessage());
        }
        return CommonResult.success(ResultCode.SUCCESS);
    }

    *//**
     * 胁迫特征查询功能
     *//*
    @ApiOperation(value = "胁迫特征查询功能")
    @PostMapping(produces = "application/json")
    public CommonResult<PageInfo<Stressfeature>> tressFeatureList(@RequestParam(value = "page", required = false, defaultValue = "1") int page,
                                                                  @RequestParam(value = "pagesize", required = false, defaultValue = "3") int pagesize) {
        try {
            PageInfo<Stressfeature> stressfeatures = stressFeatureService.selectAll(page, pagesize);
            log.info("查询所有的胁迫特征信息");
            return CommonResult.success(stressfeatures, "ok");
        } catch (DataNotExistException e) {
            log.error("胁迫特征信息表中没有数据");
            throw new DataNotExistException(e.getCode(), e.getMessage());
        }
    }

    *//**
     * 胁迫特征修改
     *//*
    @ApiOperation(value = "胁迫特征修改功能")
    @PostMapping(value = "/update", produces = "application/json")
    public CommonResult stressFeatureUpdate(Stressfeature stressfeature) {

        try {
            // 实现文件上传
            // DownLoadFiles downLoadFiles = new DownLoadFiles();
            //String paramfile = downLoadFiles.DownLoadPhoto(file1);
            //String vectfile = downLoadFiles.DownLoadPhoto(file2);
            //stressfeature.setParamfile(paramfile);
            //stressfeature.setVectfile(vectfile);
            stressFeatureService.modify(stressfeature);
            log.info("胁迫特征信息更新，更新id为：" + stressfeature.getStessid());
            //return CommonResult.success(modify);
            return CommonResult.success(ResultCode.SUCCESS);
        } catch (DataNotExistException e) {
            log.error("更新id = {}的胁迫特征信息失败", stressfeature.getStessid());
            throw new DataNotExistException(e.getCode(), e.getMessage());
        }
    }*/

}
